using Devtodo.Models;
using Microsoft.Data.Sqlite;
using Microsoft.UI.Xaml.Controls;
using System.Collections.ObjectModel;
using Windows.Storage;
namespace Devtodo.Pages;

public sealed partial class Log : Page
{
  public Log()
  {
    InitializeComponent();
    LoadList();
  }
  public ObservableCollection<LogItem> Items { get; } = [];
  async void LoadList()
  {
    Items.Clear();
    var connection = new SqliteConnection("Data Source=" + ApplicationData.Current.LocalFolder.Path + "/devtodo.db");
    await connection.OpenAsync();
    var selectCmd = new SqliteCommand("SELECT * FROM log", connection);
    var reader = await selectCmd.ExecuteReaderAsync();
    while (await reader.ReadAsync())
    {
      Items.Add(new LogItem
      {
        Id = reader.GetInt32(0),
        Table = reader.GetString(1),
        Type = reader.GetString(2),
        Time = reader.GetString(3)
      });
    }
    await connection.CloseAsync();
  }
}